import {watch, unref} from 'vue'
import { useTitle as usePageTitle } from '@vueuse/core'
import { useRouter } from 'vue-router'

export function useTitle(){
  const title = import.meta.env.VITE_APP_TITLE
  const {currentRoute} = useRouter()

  const pageTitle = usePageTitle();

  watch(
    [()=> currentRoute.value.path],
    ()=>{
      const route = unref(currentRoute)
      pageTitle.value = route.meta.title ? `${title} - ${title}` : `${title}`
    },
    {
      immediate: true
    },
  )
}